package org.dru.clay.util.functional;

/**
 * Functions
 * User: joakimd
 * Date: 2013-07-22
 * Time: 16:13
 */
public final class Functions {
    private Functions() {
    }

    public static <F> Function<F, String> getToString() {
        return ObjectFunction.TO_STRING.withNarrowedType();
    }

    private static enum ObjectFunction implements Function<Object, Object> {
        TO_STRING {
            @Override
            public Object apply(final Object value) {
                return value.toString();
            }
        };

        @SuppressWarnings("unchecked")
        public <F, T> Function<F, T> withNarrowedType() {
            return (Function<F, T>) this;
        }
    }
}
